home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / mpw yacc ƒ src / files.c < prev    next >
C/C++ Source or Header  |  1989-11-19  |  3KB  |  161 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3. #ifdef MACINTOSH
  4. #include <files.h>
  5. #endif
  6. #include "files.h"
  7. #include "new.h"
  8.  
  9. extern char dflag;
  10. extern char vflag;
  11. extern char *prefix;
  12. extern char *mktemp();
  13.  
  14. char *action_file_name = ACTION_FILE;
  15. char *defines_file_name;
  16. char *input_file_name;
  17. char *parser_file_name = PARSER_FILE;
  18. char *output_file_name;
  19. char *temp_file_name = TEMP_FILE;
  20. char *verbose_file_name;
  21.  
  22. FILE *action_file;
  23. FILE *defines_file;
  24. FILE *input_file;
  25. FILE *parser_file;
  26. FILE *output_file;
  27. FILE *temp_file;
  28. FILE *verbose_file;
  29.  
  30.  
  31. openfiles()
  32. {
  33.     int i;
  34.  
  35. #ifdef MACINTOSH
  36.     char name[256];
  37.     short refnum;
  38.     
  39.     GetVol(name,&refnum);
  40. #endif
  41.  
  42.     i = strlen(prefix);
  43.     defines_file_name = NEW2(i + sizeof(DEFINES_FILE) + 1, char);
  44.     strcpy(defines_file_name, prefix);
  45.     strcpy(defines_file_name + i, DEFINES_FILE);
  46.     output_file_name = NEW2(i + sizeof(OUTPUT_FILE) + 1, char);
  47.     strcpy(output_file_name, prefix);
  48.     strcpy(output_file_name + i, OUTPUT_FILE);
  49.     verbose_file_name = NEW2(i + sizeof(VERBOSE_FILE) + 1, char);
  50.     strcpy(verbose_file_name, prefix);
  51.     strcpy(verbose_file_name + i, VERBOSE_FILE);
  52.  
  53. #ifndef MPWC
  54.     mktemp(action_file_name);
  55.     mktemp(temp_file_name);
  56. #endif
  57.  
  58.     if (!input_file)
  59.     {
  60.     input_file = fopen(input_file_name, "r");
  61.     if (input_file == NULL) open_error(input_file_name);
  62.     }
  63.  
  64.     parser_file = fopen(parser_file_name, "r");
  65.     if (parser_file == NULL) open_error(parser_file_name);
  66.  
  67. #ifdef MACINTOSH
  68.     strcpy(name,action_file_name);
  69.     c2pstr(name);
  70.     FSDelete(name,refnum);
  71.     Create(name,refnum,'MPS ','TEXT');
  72. #endif
  73.  
  74.     action_file = fopen(action_file_name, "w");
  75.     if (action_file == NULL) open_error(action_file_name);
  76.  
  77.     if (vflag)
  78.     {
  79. #ifdef MACINTOSH
  80.     strcpy(name,verbose_file_name);
  81.     c2pstr(name);
  82.     FSDelete(name,refnum);
  83.     Create(name,refnum,'MPS ','TEXT');
  84. #endif
  85.  
  86.     verbose_file = fopen(verbose_file_name, "w");
  87.     if (verbose_file == NULL) open_error(verbose_file_name);
  88.     }
  89.  
  90.     if (dflag)
  91.     {
  92.     defines_file = fopen(defines_file_name, "r");
  93.     if (defines_file == NULL)
  94.     {
  95. #ifdef MACINTOSH
  96.         strcpy(name,defines_file_name);
  97.         c2pstr(name);
  98.         FSDelete(name,refnum);
  99.         Create(name,refnum,'MPS ','TEXT');
  100. #endif
  101.  
  102.         defines_file = fopen(defines_file_name, "w");
  103.         if (defines_file == NULL) open_error(defines_file_name);
  104.         temp_file = defines_file;
  105.     }
  106.     else
  107.     {
  108. #ifdef MACINTOSH
  109.         strcpy(name,temp_file_name);
  110.         c2pstr(name);
  111.         FSDelete(name,refnum);
  112.         Create(name,refnum,'MPS ','TEXT');
  113. #endif
  114.  
  115.         temp_file = fopen(temp_file_name, "w");
  116.         if (temp_file == NULL) temp_file = defines_file;
  117.     }
  118.     }
  119.  
  120. #ifdef MACINTOSH
  121.     strcpy(name,output_file_name);
  122.     c2pstr(name);
  123.     FSDelete(name,refnum);
  124.     Create(name,refnum,'MPS ','TEXT');
  125. #endif
  126.  
  127.     output_file = fopen(output_file_name, "w");
  128.     if (output_file == NULL) open_error(output_file_name);
  129. }
  130.  
  131. tidy()
  132. {
  133.     if (action_file != NULL)
  134.     {
  135.         fclose(action_file);
  136.         ZAPFILE(action_file_name);
  137.     }
  138.  
  139.     if (dflag)
  140.     {
  141.     if (defines_file != NULL)
  142.     {
  143.         if (defines_file == temp_file)
  144.         {
  145.         fclose(defines_file);
  146.         temp_file = NULL;
  147.         }
  148.     }
  149.     if (temp_file != NULL)
  150.     {
  151.         fclose(temp_file);
  152.         ZAPFILE(temp_file_name);
  153.     }
  154.     }
  155.  
  156.     if (vflag && verbose_file != NULL) fclose(verbose_file);
  157.     if (input_file != NULL) fclose(input_file);
  158.     if (parser_file != NULL) fclose(parser_file);
  159.     if (output_file != NULL) fclose(output_file);
  160. }
  161.